package lesson19.notepad;

import java.util.Scanner;

public class SecuredNotepad extends SimpleNotepad implements ISecuredNotepad{
	private String password;
	
	public SecuredNotepad(String password) {
		super();
		if(password != null)
			this.password = password;
	}
	
	@Override
	public void addTextToCurrentPage(final int pageNumber, final String text) {
		if(askForPassword())
			super.addTextToCurrentPage(pageNumber, text);
	}

	@Override
	public void replaceTextToCurrentPage(int pageNumber, String text)
	{
		if(askForPassword())
			super.replaceTextToCurrentPage(pageNumber, text);
	}

	
	@Override
	public void deleteTextAtCurrentPage(Page selectedPage) {
		if(askForPassword())
			super.deleteTextAtCurrentPage(selectedPage);
	}
	
	public boolean askForPassword()
	{
		return this.password.equals(enterPassword());
	}
	
	private String enterPassword()
	{
		Scanner sc = new Scanner(System.in);
		System.out.println("Enter your password");
		return sc.nextLine();
	}
		
}
